package com.example.jobback.service.seeker.impl;

import com.example.jobback.mapper.*;
import com.example.jobback.po.Deliver;
import com.example.jobback.po.Seeker;
import com.example.jobback.req.common.page.PageReq;
import com.example.jobback.resp.recruiter.deliver.SeekerProjectExperienceResp;
import com.example.jobback.resp.recruiter.deliver.SeekerResumeResp;
import com.example.jobback.resp.recruiter.deliver.SeekerWorkExperienceResp;
import com.example.jobback.resp.seeker.common.SCrossSeekerResp;
import com.example.jobback.resp.seeker.experience.project.ProjectExperienceResp;
import com.example.jobback.resp.seeker.experience.work.WorkExperienceResp;
import com.example.jobback.result.Result;
import com.example.jobback.service.seeker.SeekerCommonService;
import com.example.jobback.service.seeker.SeekerCrossService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName: SeekerCrossServiceImpl
 * @Description:跨服务-求职者接口实现类
 * @Author: lhb
 * @Date: 2025/7/12
 */
@Service
public class SeekerCrossServiceImpl implements SeekerCrossService {
    private final SeekerMapper seekerMapper;

    private final DeliverMapper deliverMapper;

    private final WorkExperienceMapper workExperienceMapper;

    private final ProjectExperienceMapper projectExperienceMapper;

    private final SeekerCommonService seekerCommonService;

    private final CollectMapper collectMapper;

    public SeekerCrossServiceImpl(SeekerMapper seekerMapper, DeliverMapper deliverMapper, SeekerCommonService seekerCommonService, WorkExperienceMapper workExperienceMapper, ProjectExperienceMapper projectExperienceMapper, CollectMapper collectMapper) {
        this.seekerMapper = seekerMapper;
        this.deliverMapper = deliverMapper;
        this.seekerCommonService = seekerCommonService;
        this.workExperienceMapper = workExperienceMapper;
        this.projectExperienceMapper = projectExperienceMapper;
        this.collectMapper = collectMapper;
    }

    @Override
    public List<Seeker> getSeekersByUserIds(List<Long> userIds) {
        return seekerMapper.getSeekerByUserIds(userIds);
    }

    @Override
    public List<Deliver> getDeliversByRecruiterUserId(Long recruiterUserId, Boolean interview) {
        return deliverMapper.getDeliversByRecruiterUserId(recruiterUserId, interview);
    }

    @Override
    public int interview(Long id, Long recruiterUserId) {
        Deliver deliver = new Deliver();
        deliver.setInterview(true);
        deliver.setId(id);
        deliver.setRecruiterUserId(recruiterUserId);
        return deliverMapper.update(deliver);
    }

    @Override
    public Deliver getDeliverByBothUserId(Long recruiterUserId, Long seekerUserId) {
        return deliverMapper.getDeliverByBothUserId(recruiterUserId, seekerUserId);
    }

    @Override
    public SeekerResumeResp getSeekerResume(Long userId) {
        Result<SCrossSeekerResp> seekerBasicMessage = seekerCommonService.getSeekerBasicMessage(userId);
        SCrossSeekerResp sCrossSeekerResp = seekerBasicMessage.getData();
        SeekerResumeResp resp = new SeekerResumeResp();
        resp.setSeekerProjectExperienceRespList(new ArrayList<>());
        resp.setSeekerWorkExperienceRespList(new ArrayList<>());
        BeanUtils.copyProperties(sCrossSeekerResp, resp);
        //映射工作经历和项目经历
        List<WorkExperienceResp> workExperience = workExperienceMapper.getWorkExperience(userId);
        List<ProjectExperienceResp> projectExperience = projectExperienceMapper.getProjectExperience(userId);
        for (WorkExperienceResp workExperienceResp : workExperience) {
            SeekerWorkExperienceResp seekerWorkExperienceResp = new SeekerWorkExperienceResp();
            BeanUtils.copyProperties(workExperienceResp, seekerWorkExperienceResp);
            resp.getSeekerWorkExperienceRespList().add(seekerWorkExperienceResp);
        }
        for (ProjectExperienceResp projectExperienceResp : projectExperience) {
            SeekerProjectExperienceResp seekerProjectExperienceResp = new SeekerProjectExperienceResp();
            BeanUtils.copyProperties(projectExperienceResp, seekerProjectExperienceResp);
            resp.getSeekerProjectExperienceRespList().add(seekerProjectExperienceResp);
        }
        return resp;
    }

    @Override
    public Long getResumeDelivers() {
        return deliverMapper.getResumeDelivers();
    }

    @Override
    public void deleteDeliverByRecruiterUserId(Long deleteUserId) {
        deliverMapper.deleteByRecruiterUserId(deleteUserId);
    }

    @Override
    public void deleteCollectByPositionIds(List<Long> positionIdList) {
        collectMapper.deleteByPositionIds(positionIdList);
    }

    @Override
    public int registerSeekerTest(Seeker seeker) {
        return seekerMapper.register(seeker);
    }
}
